home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo1.zoo / demo / icon / cycle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-24  |  3.4 KB  |  169 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: cycle.c,v 4.2 88/06/24 17:22:31 bianchi Exp $
  9.     $Source: /tmp/mgrsrc/demo/icon/RCS/cycle.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/icon/RCS/cycle.c,v $$Revision: 4.2 $";
  12.  
  13. #include <sys/time.h>
  14. #include <stdio.h>
  15. #include <signal.h>
  16. #include "term.h"
  17.  
  18. /*
  19.  * cycle -- a program to do simple flip-book animation
  20.  * Steve Hawley
  21.  */
  22.  
  23. #define fsleep(x) \
  24.    { \
  25.    struct timeval time; \
  26.    time.tv_sec = 0; \
  27.    time.tv_usec = x; \
  28.    select(0,0,0,0,&time); \
  29.    }
  30.  
  31. #define DEF_SPEED 90000
  32. #define MAXBUF 512
  33.  
  34. static char    *cmd;
  35. static int    offset;    /* where icons end (offset from argc) */
  36. static int    bitcount;    /* number of bitmaps created */
  37. static char    cwd[MAXBUF];
  38. static int    w, h;
  39.  
  40. static
  41. cleanup()
  42. {
  43.     /* be a nice program and clean up */
  44.     int i;
  45.  
  46.     m_ttyreset();            /* reset echo */
  47.     for (i = 1; i <= bitcount; i++)    /* free up bitmaps */
  48.         m_bitdestroy(i);
  49.     m_pop();            /* pop environment */
  50.     exit(0);
  51. }
  52.  
  53. main(argc,argv)
  54. char **argv;
  55. {
  56.     char    *getenv();
  57.     int    speed, i;
  58.     int    reverse = 0;
  59.     FILE    *popen(), *fp = popen("/bin/pwd", "r");
  60.  
  61.     cmd = *argv;
  62.     argc--; argv++;
  63.  
  64.     if (!fp) {
  65.         fprintf(stderr,"%s: can't get current directory\n",cmd);
  66.         exit(2);
  67.     }
  68.     fgets(cwd,sizeof(cwd),fp);
  69.     *(cwd + strlen(cwd) - 1) = '\0';  /* blah */
  70.     pclose(fp);
  71.  
  72.     if (argc < 1)
  73.         usage();
  74.  
  75.     ckmgrterm();
  76.  
  77.     m_setup(M_FLUSH);    /* flush output stream */
  78.     m_push(P_BITMAP|P_EVENT|P_FLAGS);
  79.     m_setmode(M_ABS);
  80.  
  81.     signal(SIGINT,cleanup);        /* program loops forever */
  82.     signal(SIGTERM,cleanup);    /* this gives a mechanism */
  83.     signal(SIGQUIT,cleanup);    /* for cleaning up */
  84.  
  85.     m_func(B_COPY);    /* bit copy, so we don't have to erase */
  86.     m_clear();    /* clear the screen */
  87.     m_ttyset()    ;/* no keybaord echo */
  88.  
  89.     speed = DEF_SPEED;
  90.     offset = 0;
  91.  
  92.     while( argv[0][0] == '-' ) {
  93.         switch( argv[0][1] ) {
  94.         case 's':
  95.             speed = atoi(&(argv[0][2]));
  96.             break;
  97.         case 'r':
  98.             reverse = 1;
  99.             break;
  100.         default:
  101.             usage();
  102.         }
  103.         argv++; argc--;
  104.     }
  105.  
  106.     if (argc < 1)
  107.         usage();
  108.  
  109.     for ( ; argc;  argv++, argc-- ) {
  110.         bitcount++;
  111.         loadmap( bitcount, *argv );
  112.     }
  113.     while(1) {
  114.         for (i = 1; i <= bitcount; i++) {
  115.             m_bitcopyto(0, 0, w, h, 0, 0, 0, i);
  116.             fsleep(speed);
  117.             /* delay a bit, so we can see animation */
  118.         }
  119.         if( !reverse )
  120.             continue;
  121.         for (i--;  i > 1;  i--) {
  122.             m_bitcopyto(0, 0, w, h, 0, 0, 0, i);
  123.             fsleep(speed);
  124.         }
  125.     }
  126. }
  127.  
  128.  
  129. static
  130. loadmap( i, file )
  131. int    i;
  132. char    *file;
  133. {
  134.     char    buf[MAXBUF];
  135.  
  136.     if (*file == '/')
  137.         m_bitfromfile(i, file);
  138.     else if (strncmp(file, "../", 3) == 0) {
  139.         sprintf(buf, "%s/%s", cwd, file);
  140.         m_bitfromfile(i, buf);
  141.     }
  142.     else if (strncmp(file, "./", 2) == 0) {
  143.         sprintf(buf, "%s%s", cwd, file+1);
  144.         m_bitfromfile(i, buf);
  145.     }
  146.     else {
  147.         m_bitfromfile(i, file);
  148.     }
  149.     m_gets(buf);
  150.     sscanf(buf, "%d %d", &w, &h); /* load in icons. */
  151.     if (w == 0 || h == 0) {
  152.         fprintf(stderr, "%s: %s is not a bitmap.\n", cmd, file);
  153.         cleanup();
  154.     }
  155. }
  156.  
  157.  
  158. static
  159. usage()
  160. {
  161.     fprintf(stderr, "Usage: %s [-sspeed] [-r] icon1 [icon2 ...iconn]\n",
  162.         cmd);
  163.     fputs("\
  164. -sspeed    delay `speed' microseconds between frames\n\
  165. -r    after running forward through the frames, reverse and run backwards\n",
  166.         stderr);
  167.     exit(1);
  168. }
  169.